﻿cmake_minimum_required(VERSION 2.8)
project(libxml2)
file(GLOB lib_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c)
list(REMOVE_ITEM lib_srcs xmllint.c xmlcatalog.c)
list(FILTER lib_srcs EXCLUDE REGEX "^test.*\\.c$|^run.*\\.c$")
set(CMAKE_DEBUG_POSTFIX "D")
include_directories(include ${ICONV_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${LIBLZMA_INCLUDE_DIRS} ${LIBLZMA_SOURCE_DIR}/api)
list(APPEND lib_libs ${ICONV_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBLZMA_LIBRARIES} ws2_32)
add_definitions(/DHAVE_ZLIB_H /DHAVE_LZMA_H)
add_library(${PROJECT_NAME} SHARED ${lib_srcs})
target_link_libraries(${PROJECT_NAME} ${lib_libs})
install(DIRECTORY include/libxml DESTINATION include/${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
install(EXPORT ${PROJECT_NAME}-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}-config.cmake)

if(BUILD_STATIC)
  add_library(${PROJECT_NAME}S STATIC ${lib_srcs})
  target_compile_definitions(${PROJECT_NAME}S PRIVATE LIBXML_STATIC)
  install(TARGETS ${PROJECT_NAME}S EXPORT ${PROJECT_NAME}S-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
  install(EXPORT ${PROJECT_NAME}S-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}S-config.cmake)
endif()
